package mobi.greenplate.theweb.user;

import java.util.ArrayList;
import java.util.Collection;
import mobi.greenplate.theweb.domain.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;

/**
 *
 * @author dmakariev
 */
public class UserAuthentication implements Authentication{
    private static final long serialVersionUID = 1L;

    public UserAuthentication(String userName, String password, User currentUser) {
        this.userName = userName;
        this.password = password;
        this.currentUser = currentUser;
    }

    
    private final String userName;
    private final String password;
    private final User currentUser;


    public Collection<GrantedAuthority> getAuthorities() {
        ArrayList<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
        list.add(new GrantedAuthorityImpl(currentUser.getUserRole().getLabel()));
        return list;
    }

    public Object getCredentials() {
        return password;
    }

    public Object getDetails() {
        return currentUser.getId();
    }

    public Object getPrincipal() {
        return currentUser;
    }

    public boolean isAuthenticated() {
        return true;
    }

    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        
    }

    public String getName() {
        return userName;
    }
 
}
